package com.hundsun.documentripper.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hundsun.documentripper.domain.dto.BaseResponse;
import com.hundsun.documentripper.domain.dto.UserLogView;
import com.hundsun.documentripper.domain.query.LogQuery;
import com.hundsun.documentripper.error.ErrorCatcher;
import com.hundsun.documentripper.service.UserLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Note：
 *
 * @author ：mengjw
 * @description：日志控制层
 * @date ：Created in 2021/1/26
 */
@Api("日志")
@RestController
public class UserLogController {

    @Autowired
    private UserLogService userLogService;

    @ApiOperation("分页获取操作日志列表(根据传参不同可以查询用户、产品、产品版本、文档和文件的操作日志)")
    @PostMapping("/log")
    @ErrorCatcher(code = "6001")
    public BaseResponse<IPage<UserLogView>> getUserLogViewListByPage(@RequestBody LogQuery logQuery) {
        return new BaseResponse<IPage<UserLogView>>(userLogService.getUserLogViewListByPage(logQuery));
    }

    @ApiOperation("分页获取用户最近操作日志列表")
    @PostMapping("/log/current")
    @ErrorCatcher(code = "6002")
    public BaseResponse<IPage<UserLogView>> getUserCurrentLogViewListByPage(@RequestBody LogQuery logQuery, HttpServletRequest request) {
        logQuery.setUserUuid((String) request.getSession().getAttribute("userUuid"));
        return new BaseResponse<IPage<UserLogView>>(userLogService.getUserCurrentLogViewListByPage(logQuery));
    }

}